﻿Option Strict On

Imports KUeLib.Data
Imports KUeLib.Data.ServiceDefinitions
Imports KUeLib.Vertraege
Imports System.Windows.Forms

Namespace Formulare.Vertraege

    Public Class VertraegeUebersichtForm
        Inherits WeifenLuo.WinFormsUI.Docking.DockContent
        Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions


        Private _vertraege As List(Of Vertrag)
        Private _vertragService As VertragsDataService = _
                                        ServiceManager.GetInstance.GetVertragDataService()

        Public Sub New()

            ' Dieser Aufruf ist für den Designer erforderlich.
            InitializeComponent()

            ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.

            InitializeVertraege()

        End Sub

        Public Sub InitializeVertraege()

            lbVertragsuebersicht.Items.Clear()

            _vertraege = _vertragService.GetVertraege()

            For Each v As Vertrag In _vertraege
                Dim lvi As ListViewItem = lbVertragsuebersicht.Items.Add(v.Bezeichnung)
                lvi.SubItems.Add(v.Partner)
                lvi.SubItems.Add(v.Status)
                lvi.SubItems.Add(v.Zahlungsintervall)
                lvi.SubItems.Add(v.Betrag.ToString("C", (New System.Globalization.CultureInfo("de-DE")).NumberFormat))
            Next

        End Sub

        Private Sub lbVertragsuebersicht_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lbVertragsuebersicht.MouseDoubleClick
            Call OpenSelected()
        End Sub

        Private Sub btnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Call InitializeVertraege()
        End Sub

        Public Sub Delete() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Delete

        End Sub

        Public Sub [New]() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.New

            Dim vdf As New Formulare.Vertraege.VertragForm
            vdf.Show(Me.DockPanel)

        End Sub

        Public Sub Open() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Open
            Call OpenSelected()
        End Sub

        Public Event OptionsChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.OptionsChanged

        Public Sub PagePreview() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.PagePreview

        End Sub

        Public Sub Print() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Print

        End Sub

        Public Sub Refresh1() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Refresh
            Call InitializeVertraege()
        End Sub

        Public Sub Save() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.Save

        End Sub

        Public Sub SaveAs() Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SaveAs

        End Sub

        Public ReadOnly Property SetCoopDesign As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetCoopDesign
            Get
                Return False
            End Get
        End Property

        Public ReadOnly Property SetDelete As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetDelete
            Get
                Return False
            End Get
        End Property

        Public ReadOnly Property SetNew As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetNew
            Get
                Return True
            End Get
        End Property

        Public ReadOnly Property SetOpen As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetOpen
            Get
                Return (lbVertragsuebersicht.SelectedIndices.Count > 0)
            End Get
        End Property

        Public ReadOnly Property SetPagePreview As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetPagePreview
            Get
                Return False
            End Get
        End Property

        Public ReadOnly Property SetPrint As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetPrint
            Get
                Return False
            End Get
        End Property

        Public ReadOnly Property SetRefresh As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetRefresh
            Get
                Return True
            End Get
        End Property

        Public ReadOnly Property SetSave As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetSave
            Get
                Return False
            End Get
        End Property

        Public ReadOnly Property SetSaveAs As Boolean Implements LibMultiPlug.Core.Plugins.Interfaces.IFormOptions.SetSaveAs
            Get
                Return False
            End Get
        End Property

        Private Sub OpenSelected()
            If lbVertragsuebersicht.SelectedItems.Count > 0 Then
                Dim vf As New VertragForm
                vf.Show(Me.DockPanel, _vertraege(lbVertragsuebersicht.SelectedIndices(0)).Id)
            End If
        End Sub

        Private Sub lbVertragsuebersicht_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbVertragsuebersicht.SelectedIndexChanged
            RaiseEvent OptionsChanged(Me, Nothing)
        End Sub
    End Class

End Namespace